package pl.kaczmarz.audiosteganography;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author Pawel
 */
public class KeyFile {
	private double blockLength;
	private double zeroDelay;
	private double oneDelay;
	private int messageLength;
	private int messageRepeat;

	public double getBlockLength() {
		return blockLength;
	}

	public void setBlockLength(double blockLength) {
		this.blockLength = blockLength;
	}

	public int getMessageLength() {
		return messageLength;
	}

	public void setMessageLength(int messageLength) {
		this.messageLength = messageLength;
	}

	public int getMessageRepeat() {
		return messageRepeat;
	}

	public void setMessageRepeat(int messageRepeat) {
		this.messageRepeat = messageRepeat;
	}

	public double getOneDelay() {
		return oneDelay;
	}

	public void setOneDelay(double oneDelay) {
		this.oneDelay = oneDelay;
	}

	public double getZeroDelay() {
		return zeroDelay;
	}

	public void setZeroDelay(double zeroDelay) {
		this.zeroDelay = zeroDelay;
	}

	public static KeyFile load(String fileName) throws FileNotFoundException, IOException {
		try (BufferedReader file = new BufferedReader(new FileReader(fileName))) {
			KeyFile keyFile = new KeyFile();
			keyFile.setBlockLength(Double.parseDouble(file.readLine()));
			keyFile.setZeroDelay(Double.parseDouble(file.readLine()));
			keyFile.setOneDelay(Double.parseDouble(file.readLine()));
			keyFile.setMessageLength(Integer.parseInt(file.readLine()));
			keyFile.setMessageRepeat(Integer.parseInt(file.readLine()));
			return keyFile;
		}
	}

	public void save(String fileName) throws IOException {
		try (BufferedWriter file = new BufferedWriter(new FileWriter(fileName))) {
			file.write(Double.toString(getBlockLength()));
			file.newLine();
			file.write(Double.toString(getZeroDelay()));
			file.newLine();
			file.write(Double.toString(getOneDelay()));
			file.newLine();
			file.write(Integer.toString(getMessageLength()));
			file.newLine();
			file.write(Integer.toString(getMessageRepeat()));
		}
	}
}
